#include <iostream>

using namespace std;
//电脑主要组成部件为 CPU（用于计算），显卡（用于显示），内存条（用于存储）
//将每个零件封装出抽象基类，并且提供不同的厂商生产不同的零件，例如Intel厂商和Lenovo厂商
//创建电脑类提供让电脑工作的函数，并且调用每个零件工作的接口
//测试时组装三台不同的电脑进行工作

//抽象CPU类
class CPU {
public:
    //抽象的计算函数
    virtual void calculate() = 0;
};

//抽象显卡类
class GPU {
public:
    //抽象的显示函数
    virtual void display() = 0;
};

//抽象内存条类
class Memory {
public:
    //抽象的存储函数
    virtual void storage() = 0;
};

//电脑类
class Computer {
private:
    CPU *cpu;//CPU的零件指针
    GPU *gpu;//GPU的零件指针
    Memory *memory;//内存条的零件指针
public:
    Computer(CPU *cpu, GPU *gpu, Memory *memory) {
        this->cpu = cpu;
        this->gpu = gpu;
        this->memory = memory;
    }

    //提供工作函数
    void work() {
        cpu->calculate();
        gpu->display();
        memory->storage();
    }

    //提供析构函数
    ~Computer() {
        //释放CPU零件
        if (cpu != nullptr) {
            delete cpu;
            cpu = nullptr;
        }
        //释放GPU零件
        if (gpu != nullptr) {
            delete gpu;
            gpu = nullptr;
        }
        //释放内存条零件
        if (memory != nullptr) {
            delete memory;
            memory = nullptr;
        }
    }
};

//具体厂商
//Intel厂商
class IntelCPU : public CPU {
public:
    void calculate() {
        cout << "Intel的CPU开始计算了!" << endl;
    }
};

class IntelGPU : public GPU {
public:
    void display() {
        cout << "Intel的GPU开始显示了!" << endl;
    }
};

class IntelMemory : public Memory {
public:
    void storage() {
        cout << "Intel的内存条开始存储了!" << endl;
    }
};

//AMd厂商
class AMDCPU : public CPU {
public:
    void calculate() {
        cout << "AMD的CPU开始计算了!" << endl;
    }
};

class AMDGPU : public GPU {
public:
    void display() {
        cout << "AMD的GPU开始显示了!" << endl;
    }
};

class AMDMemory : public Memory {
public:
    void storage() {
        cout << "AMD的内存条开始存储了!" << endl;
    }
};

void test() {
    //第一台电脑零件
    CPU *intelCPU = new IntelCPU;
    GPU *intelGPU = new IntelGPU;
    Memory *intelMemory = new IntelMemory;
    cout << "第一台电脑开始工作了:" << endl;
    Computer *computer1 = new Computer(intelCPU, intelGPU, intelMemory);
    computer1->work();
    delete computer1;
    //第一台电脑零件
    cout << "第二台电脑开始工作了:" << endl;
    Computer *computer2 = new Computer(new AMDCPU, new AMDGPU, new AMDMemory);
    computer2->work();
    delete computer2;

    cout << "第三台电脑开始工作了:" << endl;
    Computer *computer3 = new Computer(new AMDCPU, new IntelGPU, new AMDMemory);
    computer3->work();
    delete computer2;
}

int main() {
    test();
    return 0;
}